const form=document.querySelector('.user-form');
const userCheck=new FieldValidator('txtLoginId',async (val)=>{
    const resp=await API.exists(val)
    if(!val){
        return '请填写账号'
    }
    if(resp.data){
        return '账号已存在'
    }
})
const nicknameCheck=new FieldValidator('txtNickname',async (val)=>{
    if(!val){
        return '请填写昵称'
    }
})
const pwdCheck=new FieldValidator('txtLoginPwd',async (val)=>{
    if(!val){
        return '请填写密码'
    }
})
const rePwdCheck=new FieldValidator('txtLoginPwdConfirm',async (val)=>{
    if(!val){
        return '请再次输入密码'
    }
    if(val!==pwdCheck.input.value){
        return '两次密码不一致'
    }
})
form.onsubmit=async (e)=>{
    e.preventDefault();
    const result=FieldValidator.runAllcheck(userCheck,nicknameCheck,pwdCheck,rePwdCheck);
    if(result){
        const resp=await API.reg({
            loginId:userCheck.input.value,
            nickname:nicknameCheck.input.value,
            loginPwd:pwdCheck.input.value
        })
        if(resp.code===0){
            alert('注册成功,跳转至登录页面')
            location.href = './login.html';
        }
    }else{
        return
    }
}